package com.ruoyi.merchant.controller;

import com.ruoyi.common.core.cg.pojo.Image;
import com.ruoyi.merchant.service.PngService;
import com.ruoyi.merchant.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/png")
public class PngController {

    @Autowired
    private PngService pngService;

    @PostMapping("/save")
    public Result<Image> pngSave(
            @RequestParam("frontIdCard") MultipartFile frontIdCard,
            @RequestParam("sideIdCard") MultipartFile sideIdCard,
            @RequestParam("license") MultipartFile license,
            @RequestParam("foodHygieneApproval") MultipartFile foodHygieneApproval,
            @RequestParam("uid") Integer uid
    ) {
        try {
            // 调用 Service 层的 pngSave 方法处理文件上传和数据库保存
            Image png = pngService.pngSave(frontIdCard, sideIdCard, license, foodHygieneApproval,uid);
            return Result.ok(png);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.build(500, "保存失败：" + e.getMessage(), null);
        }
    }
}


